#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
description: please input using description
author: justbk
date: 2022/7/26
modify_records:
    - 2022/7/26 justbk create this file
"""
import os
import sys
PSYCOPG2_ROOT = '/home/zhoubin/code/openGauss-connector-python-psycopg2/output/'
sys.path.insert(0, PSYCOPG2_ROOT)
import psycopg2
connector_args = {
    'database': 'postgres',
    'user': 'test',
    'password': 'Zhoubin@123',
    'host': '20.20.20.52',
    'port': '10101'
}

tinyint_type = psycopg2.extensions.new_type((5545,), 'tinyint', lambda s, conn_or_curs: int(s))
psycopg2.extensions.register_type(tinyint_type, None)
def test_connect():
    conn = None
    try:
        conn = psycopg2.connect(**connector_args)
        curs = conn.cursor()
        curs.execute('drop table if exists t1;')
        curs.execute('create table t1(col tinyint);')
        curs.execute('insert into t1 values (%s);', (255,))
        curs.execute('select * from t1;')
        x = curs.fetchone()
        print(type(x[0]), x)
    except Exception as exp:
        print('print error:%s'%(exp))
    finally:
        if conn is not None:
            conn.close()
test_connect()

